C=gcc
CC=g++
CFLAGS=-Wall -pedantic -pedantic-errors -g -ggdb -DDEBUG
LDFLAGS=
BINF=../bin/tcp
HEADER_DIR=..

SHARED_SOURCES := $(shell find ../*/ -name '[Logger|Lock]*.cpp')
SHARED_OBJ=$(SHARED_SOURCES:.cpp=.o)

TCP_SERVER_EMISOR_SOURCES=tcpserver_emisor.cpp
TCP_SERVER_EMISOR_OBJ=$(TCP_SERVER_EMISOR_SOURCES:.cpp=.o)
TCP_SERVER_EMISOR_BIN=$(BINF)/tcpserver_emisor

TCP_SERVER_RECEPTOR_SOURCES=tcpserver_receptor.cpp
TCP_SERVER_RECEPTOR_OBJ=$(TCP_SERVER_RECEPTOR_SOURCES:.cpp=.o)
TCP_SERVER_RECEPTOR_BIN=$(BINF)/tcpserver_receptor

TCP_CLIENT_EMISOR_SOURCES=tcpclient_emisor.cpp
TCP_CLIENT_EMISOR_OBJ=$(TCP_CLIENT_EMISOR_SOURCES:.cpp=.o)
TCP_CLIENT_EMISOR_BIN=$(BINF)/tcpclient_emisor

TCP_CLIENT_RECEPTOR_SOURCES=tcpclient_receptor.cpp
TCP_CLIENT_RECEPTOR_OBJ=$(TCP_CLIENT_RECEPTOR_SOURCES:.cpp=.o)
TCP_CLIENT_RECEPTOR_BIN=$(BINF)/tcpclient_receptor

all: tcpServerEmisor tcpServerReceptor tcpClientEmisor tcpClientReceptor 

tcpServerEmisor: $(TCP_SERVER_EMISOR_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(TCP_SERVER_EMISOR_OBJ) -o $(TCP_SERVER_EMISOR_BIN) -I$(HEADER_DIR)

tcpServerReceptor: $(TCP_SERVER_RECEPTOR_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(TCP_SERVER_RECEPTOR_OBJ) -o $(TCP_SERVER_RECEPTOR_BIN) -I$(HEADER_DIR)

tcpClientEmisor: $(TCP_CLIENT_EMISOR_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(TCP_CLIENT_EMISOR_OBJ) -o $(TCP_CLIENT_EMISOR_BIN) -I$(HEADER_DIR)

tcpClientReceptor: $(TCP_CLIENT_RECEPTOR_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(TCP_CLIENT_RECEPTOR_OBJ) -o $(TCP_CLIENT_RECEPTOR_BIN) -I$(HEADER_DIR)

.cpp.o:
	$(CC) $(CFLAGS) -I$(HEADER_DIR) -c $< -o $@

clean:
	$(RM) $(TCP_SERVER_EMISOR_OBJ) $(TCP_SERVER_EMISOR_BIN) $(TCP_SERVER_RECEPTOR_OBJ) $(TCP_SERVER_RECEPTOR_BIN) $(TCP_CLIENT_EMISOR_OBJ) $(TCP_CLIENT_EMISOR_BIN) $(TCP_CLIENT_RECEPTOR_OBJ) $(TCP_CLIENT_RECEPTOR_BIN)
